<?php
if (isset($_SESSION['admin-login'])) {
	if (isset($_SESSION['status-blog-new'])) {
		echo "<p>".$_SESSION['status-blog-new']."</p>";
		unset($_SESSION['status-blog-new']);
	}
	?>
	<html><body>
	<form action="<?php echo site()."/".$param[0] ?>/blog-new-action" method="post" onsubmit="return validateBlog()">
		Judul :<br><input type="text" name="judul" /><br>
		Isi :<br><textarea name="textform"></textarea><br>
		<input type="submit" name="post" id="post" value="Post" disabled="disabled" />
	</form>
	<a href="<?php echo site()."/".$param[0]."/blog" ?>">Cancel</a>
	<script type="text/javascript">
	document.getElementById("post").removeAttribute("disabled");
	function validateBlog() {
		var body = document.getElementsByTagName("body")[0];
		var form = document.getElementsByTagName("form")[0];
		var judul = form["judul"].value;
		var textform = form["textform"].value;
		var status = document.getElementsByTagName("p")[0] || document.createElement("p");
		if (judul.length == 0 || textform.length == 0) {
			status.innerHTML = "Semua input harus diisi";
			body.insertBefore(status,form);
		} else {
			if (document.getElementsByTagName('p')[0])
				body.removeChild(document.getElementsByTagName('p')[0]);
			return true;
		}
		return false;
	}
	</script>
	</body></html>
	<?php
} else {
	$_SESSION['status-login'] = "Log in terlebih dahulu untuk melanjutkan";
	header("Location: ".site()."/".$param[0]."/login");
}
?>